<template>
  <view v-if="miao > 0" class="container">
    <image :src="path_s_url.length > 0 ? path_s_url : path_s"></image>
    <view class="loadbtm">
      <view :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" class="cliadv loop_s_b_s" @tap="cliadv">
        {{ btntext }}
        <text class="ico"> {{ miao }}s</text>
      </view>
    </view>
  </view>
</template>

<script>
var a;
var e = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
  data() {
    return {
      miao: 0,
      loading: '',
      pagePath: '',
      btntext: '',
      path_s: '',
      path_s_url: '',
      color: '',
      rgbcolor: ''
    };
  },
  onLoad: function (i) {
    var that = this;
    app.globalData.ajax({
      url: 'loading.php',
      data: {
        submitok: 'getvar'
      },
      success: function (t) {
        if (1 == t.flag) {
          a = t.loading.pagePath;
          if (e.empty(a)) {
            a = '/pages/index/index4';
          }
          that.setData({
            loading: t.loading,
            miao: t.loading.miao,
            pagePath: a,
            btntext: t.loading.btntext,
            path_s: t.loading.path_s,
            path_s_url: t.loading.path_s_url,
            color: t.color,
            rgbcolor: e.c16_rgb(t.color)
          });
          if (0 == t.loading.miao) {
            uni.switchTab({
              url: '/pages/index/index4'
            });
          } else {
            that.time = setInterval(function () {
              that.setData({
                miao: that.miao - 1
              });
              if (0 == that.miao) {
                clearInterval(that.time);
                if ('/pages/index/index4' == a || '/pages/user/user' == a || '/pages/hn/hn' == a) {
                  uni.switchTab({
                    url: a
                  });
                } else {
                  uni.reLaunch({
                    url: a
                  });
                }
              }
            }, 1000);
          }
        } else {
          uni.showToast({
            title: t.msg,
            icon: 'none',
            mask: true
          });
        }
      }
    });
  },
  onShareAppMessage: function () {
    return {
      imageUrl: this.loading.share.imgurl,
      title: this.loading.share.title,
      path: '/pages/loading/loading'
    };
  },
  onShareTimeline: function () {
    return {
      imageUrl: this.loading.share.imgurl,
      title: this.loading.share.title,
      query: '',
      path: '/pages/loading/loading'
    };
  },
  methods: {
    cliadv: function () {
      clearInterval(this.time);
      '/pages/index/index4' == a || '/pages/user/user' == a || '/pages/hn/hn' == a
          ? uni.switchTab({
            url: a
          })
          : uni.reLaunch({
            url: a
          });
    }
  }
};
</script>
<style>
@import 'loading.css';
</style>
